package cn.com.lsjz.nursemanager.controller.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.com.lsjz.commons.result.ResultModel;
import cn.com.lsjz.nursemanager.model.system.SysOperation;
import cn.com.lsjz.nursemanager.service.system.SysOperationService;

/**
 * 菜单请求头部分
 * @author liucan
 *
 */
@RequestMapping("/admin/module")
@RestController
public class SysOperationController {

	@Autowired
	private SysOperationService sysOperationService;
	
	@RequestMapping(value="/parent/{pid}",method=RequestMethod.POST)
	public ResultModel loadParentModule(@PathVariable(value="pid") Integer parentId) {
		List<SysOperation> moduleDicts = sysOperationService.loadModuleByParentId(parentId);
		return new ResultModel(true, moduleDicts, "获取子级菜单成功");
	}
	
	@RequestMapping(value="loadParentModule",method=RequestMethod.POST)
	public ResultModel loadParentModule() {
		List<SysOperation> moduleDicts = sysOperationService.loadParentModule();
		return new ResultModel(true, moduleDicts, "获取父级菜单成功");
	}
	
	@RequestMapping(value="/{moduleId}",method=RequestMethod.GET)
	public ResultModel getModuleById(@PathVariable(value="moduleId",required=true) Integer moduleId) {
		SysOperation moduleDict = sysOperationService.getModuleById(moduleId);
		return new ResultModel(true, moduleDict, "获取单条记录成功");
	}
	
	@RequestMapping(value="/loadModuleList",method=RequestMethod.POST)
	public ResultModel loadModuleList() {
		List<SysOperation> moduleList = sysOperationService.loadModuleList();
		return new ResultModel(true, moduleList, "查询所有菜单成功");
	}
	
	
	@RequestMapping(method=RequestMethod.POST)
	public ResultModel saveModule(SysOperation moduleDict) {
		sysOperationService.addModule(moduleDict);
		return new ResultModel(true, null, "新增成功");
	}
	
	@RequestMapping(value="/parent",method=RequestMethod.POST)
	public ResultModel saveParentModule(SysOperation moduleDict) {
		sysOperationService.addModule(moduleDict);
		return new ResultModel(true, null, "新增成功");
	}
	
	@RequestMapping(method=RequestMethod.PUT)
	public ResultModel editModule(SysOperation moduleDict) {
		sysOperationService.editModule(moduleDict);
		return new ResultModel(true, null, "更新成功");
	}
	
	@RequestMapping(method=RequestMethod.DELETE,value="/{moduleId}")
	public ResultModel delModule(@PathVariable(value="moduleId",required=true)  Integer moduleId) {
		sysOperationService.delModule(moduleId);
		return new ResultModel(true, null, "删除成功");
	}
	
	@RequestMapping(value="/active",method=RequestMethod.POST)
	public ResultModel activeModule(Integer moduleId,Integer active) {
		sysOperationService.activeModule(moduleId, active);
		return new ResultModel(true, null, active == 0 ? "停用成功" : "启用成功");
	}
	
}
